package org.pzy.springboot.controller;

import org.pzy.springboot.service.WordExportService;
import org.pzy.springboot.service.WordImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("word")
public class WordController {

    @Autowired
    private WordExportService wordExportService;

    @Autowired
    private WordImportService wordImportService;

    @GetMapping("export")
    public void exportWord(HttpServletResponse response) throws IOException {
        List<String[]> data = List.of(
                new String[]{"序号", "名称", "查验情况"},
                new String[]{"项目建设资料", "A", "1"},
                new String[]{"房地产开发企业营业执照、资质证书", "B", "2"},
                new String[]{"房地产开发项目批准文件", "C", "3"}
        );
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment;filename=test.docx");
        wordExportService.exportWordWithTable(response.getOutputStream(), data);
    }

    @PostMapping("import")
    public List<String[]> importWord(@RequestParam("file") MultipartFile file) throws IOException {
        return wordImportService.importWordWithTable(file.getInputStream());
    }
}


